function isNamesValid()
{
    var firstName = document.getElementById( 'first_name' ).value;
    var lastName = document.getElementById( 'last_name' ).value;

    if ( firstName.match( /[^A-Za-z]/ ) )
    {
        throw "Invalid characters in the First Name!";
    }
    if ( lastName.match( /[^A-Za-z]/ ) )
    {
        throw "Invalid characters in the Last Name!";
    }
    if ( ( firstName.length < 2 ) || ( lastName.length < 2 ) )
    {
        throw "The field of first name and last name must have a minimum length of 2 characters!";
    }
    return true;
}

function isEmailsValid()
{
    var email = document.getElementById( 'reg_email' ).value;
    var reEmail = document.getElementById( 'reg_re_email' ).value;
    
    if ( email.length == 0 )
    {
        throw "Enter the E-Mail!";
    }
    if ( !email.match( /[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}$/ ) )
    {   
        throw "Incorrect E-Mail!";
    }
    if ( email != reEmail )
    {
        throw "E-Mail fields are not the same!";
    }
    return true;
}

function isPasswordValid()
{
    var password = document.getElementById( 'reg_password' ).value;
    if ( password.length < 6 )
    {
        throw "Password must be minimum 6 symbols long!";
    }
    if ( password.match( /[^a-zA-Z0-9]/ ) )
    {
        throw "Invalid characters in the password!";
    }
    return true;
}

function allChoicesAreMade()
{
    var sex = document.getElementById( 'sex' ).value;
    var month = document.getElementById( 'month' ).value;
    var day = document.getElementById( 'day' ).value;
    var year = document.getElementById( 'year' ).value;

    var isChoicesAreMade = ( sex != 'none') && ( month != 'none' ) && ( day != 'none' ) && ( year != 'none' );
    if ( !isChoicesAreMade )
    {
        throw "Make a selection in all fields!";
    }
    return true
}

function checkRegistrationData()
{
    if ( !document.getElementById( 'reg_form' ) )
    {
        return true;
    }
    try
    {
        var isDataValid = isNamesValid() && isEmailsValid() && isPasswordValid() && allChoicesAreMade();
    }
    catch ( error )
    {
        alert( error );
        return false;
    }
    if ( isDataValid  )
    {
        return confirm( "Are you sure?" );
    }
}